package com.jinglvhuanjing.app.utils;

import android.content.Context;
import android.content.res.AssetManager;
import android.os.Environment;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class Constants {

    // 配置文件夹路径
    public static final String SD_PATH = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ljflFolder/";
    // 配置文件文件名
    public static final String configFile = "config.ini";
    // 视频文件名字段的key
    public static final String VIDEO_FILE_NAME = "videoFileName";
    // 左侧标题内容-分类站所在小区
    public static final String LEFT_TITLE = "leftTitle";
    // 设备id-分类站编号
    public static final String DEVICE_ID = "deviceId";
    // 登录账号
    public static final String ACCOUNT = "account";
    // 天气-城市id
    public static final String CITYID = "cityId";
    // 天气-对象
    public static final String CITY_BEAN = "cityBean";
    // 服务器ip
    public static final String SERVER_IP = "ServerIP";
    // 服务器port
    public static final String SERVER_PORT = "ServerPort";
    // 版本号
    public static final String VERSION = "version";
    // 数据传输间隔(单位：ms)
    public static final String INTERVAL_TIME = "IntervalTime";
    // 关门时间间隔(单位：ms)
    public static final String CLOSE_TIME = "CloseTime";
    // 开门后下发的指令延迟时间(单位：ms)
    public static final String OPEN_DOOR_END_INTERVAL_TIME = "openDoorEndIntervalTime";
    // ICCID
    public static final String ICCID = "ICCID";
    // 打开日志标志
    public static final String OPEN_LOG = "openLog";

    // 是否是游客登录
    public static boolean isYK = true;

    // 天气地址
    public static final String TIANQI_URL = "https://v0.yiketianqi.com/api?unescape=1&version=v61&appid=14832838&appsecret=p5TrAmyD&cityid=";

    /**
     * 安装assert中的apk安装包,在6.0手机无权限安装内存的应用
     *
     * @param context
     * @param fileName
     */
    public static boolean copyFromAssert(Context context, String fileName) {
        AssetManager assetManager = context.getAssets();
        InputStream in = null;
        OutputStream out = null;

        try {
            in = assetManager.open(fileName);
            out = new FileOutputStream(Constants.SD_PATH + fileName);

            byte[] buffer = new byte[1024];

            int read;
            while ((read = in.read(buffer)) != -1) {
                out.write(buffer, 0, read);
            }

            in.close();
            in = null;

            out.flush();
            out.close();
            out = null;

            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
